<?php

namespace app\api\controller;


use app\common\controller\Api;
use app\api\model\UserCoupon as UserCouponModel;
use app\api\model\hotel\Hotel as HotelModel;

/**
 * 优惠券接口
 */
class Coupon extends Api
{
    //protected $noNeedLogin = ['expireCoupon'];

    protected $noNeedRight = ['*'];


    //我的优惠券列表
    public function myCouponList()
    {
        $param = $this->request->param();
        $param['user_id'] = $this->auth->id;
        $list = UserCouponModel::tableList($param);

        foreach ($list as $item) {
            if ($item->couponinfo) {
                $hotel = HotelModel::where('hotel_id','in',$item->couponinfo->hotel_id)->column('hotel_name');
                $item->hotel_name = $hotel?$hotel:'';
                //$item->coupon->id = is_numeric($item->coupon->id) ? IntCode::encode($item->coupon->id) : $item->coupon->id;
                $item->coupon_id = $item->couponinfo->id;
                $rd = $item->couponinfo->result_data;
                $item->result_tips = '订单满' . $rd['money'] . ($item->couponinfo->result ? '减' : '打') . $rd['number'] . ($item->couponinfo->result ? '元' : '折');
            }
            $item->expired = $item->expire_time < time();
            $item->begin = $item->begin_time < time();
        }
        $this->success('获取成功！', $list);
    }


}